<?php

/*
	info: 活动管理
*/

require dirname(__FILE__).'/include/common.inc.php';

//用户
if ($webglobal['action']=='user')
{
	$tempdefaultpagenum = 20;
	global_CheckPost(
				array(
					array('pid','int','','',0,-1),
					array('sid','int','','',0,0),
					array('status','int','','',0,0),
					array('searchkey','str','','',0,''),
					array('perpage','int','@>0','',0,$tempdefaultpagenum),
			));

	//默认载入最新活动
	if ($webglobal['CPP']['pid'] < 0)
	{
		$tempdata = $db->GetOne("SELECT id FROM promotion ORDER BY id DESC LIMIT 0,1");
		if (!empty($tempdata))
		{
			$webglobal['CPP']['pid'] = $tempdata['id'];
		}
	}

	if ($webglobal['CPP']['sid']>0 && $webglobal['CPP']['pid']<=0)
	{
		$webglobal['CPP']['sid'] = 0;
	}

	$webglobal['pinfo'] = array();
	if ($webglobal['CPP']['pid'] > 0)
	{
		$webglobal['pinfo'] = $db->GetOne("SELECT * FROM promotion WHERE id='{$webglobal['CPP']['pid']}'");

		$query = $db->Query("SELECT * FROM promotion_site WHERE pid='{$webglobal['CPP']['pid']}' ORDER BY id DESC");
		$webglobal['sinfo'] = array();
		while ($tempdata = $db->FetchArray($query))
		{
			$tempdata['begintime_show'] = !empty($tempdata['begintime']) ? global_FormatTime($tempdata['begintime']) : '';
			$webglobal['sinfo'][$tempdata['id']] = $tempdata;
		}
	}

	//搜索条件处理
	$tempsearchsql = array();
	$webglobal['searchurl'] = "&action={$webglobal['action']}";	//搜索条件
	$webglobal['searchurl'] .= "&pid={$webglobal['CPP']['pid']}";
	if ($webglobal['CPP']['pid'] > 0)
	{
		$tempsearchsql[] = "U.pid='{$webglobal['CPP']['pid']}'";
	}
	if ($webglobal['CPP']['sid'] > 0)
	{
		$tempsearchsql[] = "U.sid='{$webglobal['CPP']['sid']}'";
		$webglobal['searchurl'] .= "&sid={$webglobal['CPP']['sid']}";
	}
	if ($webglobal['CPP']['status'] >= 0)
	{
		if ($webglobal['CPP']['status'] == 1)
		{
			$tempsearchsql[] = "U.peoplenum='0'";
		}
		else
		{
			$tempsearchsql[] = "U.peoplenum>0";
		}
		$webglobal['searchurl'] .= "&status={$webglobal['CPP']['status']}";
	}
	if ($webglobal['CPP']['searchkey'] != '')
	{
		$tempsearchfield = array('B.truename','B.mobile','B.email','U.code');
		$tempsearchsql[] = $db->BuildSearchSql($webglobal['CPP']['searchkey'], $tempsearchfield);
		$webglobal['searchurl'] .= "&searchkey=".urlencode($webglobal['CPP']['searchkey']);
	}
	//排序设定处理
	$tempshowurl = '';
	if ($webglobal['CPP']['perpage'] != $tempdefaultpagenum)
	{
		$tempshowurl .= "&perpage={$webglobal['CPP']['perpage']}";
	}
	$webglobal['gourl'] = $webglobal['searchurl'].$tempshowurl."&page={$webrequest['page']}";	//整体页面条件
	$webglobal['gourlencode'] = urlencode($webglobal['gourl']);

	$tempsearchsql = empty($tempsearchsql) ? '' : ' WHERE '.implode(' AND ', $tempsearchsql);
	$webglobal['perpage'] = $webglobal['CPP']['perpage'];
	$webglobal['datanum'] = $db->GetNum("SELECT COUNT(*) FROM promotion_user U LEFT JOIN user B ON(U.uid=B.uid){$tempsearchsql}");
	if ($webglobal['datanum'] > 0)
	{
		$webglobal['page'] = global_Page($webglobal['datanum'], $webglobal['perpage'], $webrequest['page'], WEBURLPATH."/{$webserver['curfilename']}.php?{$webglobal['searchurl']}{$tempshowurl}&page=@@");
		$tempstartnum = ($webrequest['page']-1)*$webglobal['perpage'];
		$temporderstr = "U.id DESC";
		$query = $db->Query("SELECT U.*,B.truename,B.email,B.mobile,B.weddingdate,P.title,S.sitename FROM promotion_user U LEFT JOIN user B ON(U.uid=B.uid) LEFT JOIN promotion P ON (U.pid=P.id) LEFT JOIN promotion_site S ON (U.sid=S.id){$tempsearchsql} ORDER BY {$temporderstr} LIMIT $tempstartnum, {$webglobal['perpage']}");
		$webglobal['dataarray'] = array();
		$tempuserary = array();
		while ($tempdata = $db->FetchArray($query))
		{
			$tempdata['weddingdate_show'] = !empty($tempdata['weddingdate']) ? global_FormatTime($tempdata['weddingdate'], 'jS F Y') : '';
			$tempdata['codetime_show'] = !empty($tempdata['codetime']) ? global_FormatTime($tempdata['codetime']) : '';
			$tempdata['addtime_show'] = !empty($tempdata['addtime']) ? global_FormatTime($tempdata['addtime']) : '';
			$webglobal['dataarray'][$tempdata['id']] = $tempdata;
		}
	}
}
//用户预定删除
elseif ($webglobal['action']=='userdel')
{
	if ($webglobal['doit']==1)
	{
		$webglobal['id'] = isset($webrequest['id']) ? intval($webrequest['id']) : 0;
		if ($webglobal['id']<=0)
		{
			global_ShowMessage('参数错误。', '', 'BACK');
		}
		else
		{
			$tempdata = $db->GetOne("SELECT * FROM promotion_user WHERE id='{$webglobal['id']}'");
			if (empty($tempdata))
			{
				global_ShowMessage('参数错误。', '', 'BACK');
			}
			if ($tempdata['peoplenum'] > 0)
			{
				$db->Update('promotion_user', array('sid'=>0,'peoplenum'=>0,'addtime'=>0), "id='{$webglobal['id']}'");
				$db->Update('promotion_site', "curpeoplenum=curpeoplenum-{$tempdata['peoplenum']}", "id='{$tempdata['sid']}'");
				global_ShowMessage('用户预定信息已被清除。', WEBURLPATH."/{$webserver['curfilename']}.php?{$webglobal['gourl']}");
			}
			else
			{
				$db->Delete('promotion_user', "id='{$webglobal['id']}'");
				global_ShowMessage('用户激活信息删除成功。', WEBURLPATH."/{$webserver['curfilename']}.php?{$webglobal['gourl']}");
			}
		}
	}
	else
	{
		exit();
	}
}
//场所列表
elseif ($webglobal['action']=='site')
{
	$webglobal['pid'] = isset($webrequest['pid']) ? intval($webrequest['pid']) : 0;
	$webglobal['pinfo'] = array();
	if ($webglobal['pid'] > 0)
	{
		$webglobal['pinfo'] = $db->GetOne("SELECT * FROM promotion WHERE id='{$webglobal['pid']}'");
	}
	if (empty($webglobal['pinfo']))
	{
		global_ShowMessage('没有对应条目', '', 'BACK');
	}

	$query = $db->Query("SELECT * FROM promotion_site WHERE pid='{$webglobal['pid']}' ORDER BY id DESC");
	$webglobal['dataarray'] = array();
	while ($tempdata = $db->FetchArray($query))
	{
		$tempdata['begintime_show'] = !empty($tempdata['begintime']) ? global_FormatTime($tempdata['begintime']) : '';
		$webglobal['dataarray'][$tempdata['id']] = $tempdata;
	}
	$webglobal['datanum'] = count($webglobal['dataarray']);
}
//场所添加
elseif ($webglobal['action']=='siteadd')
{
	$webglobal['pid'] = isset($webrequest['pid']) ? intval($webrequest['pid']) : 0;
	$webglobal['pinfo'] = array();
	if ($webglobal['pid'] > 0)
	{
		$webglobal['pinfo'] = $db->GetOne("SELECT * FROM promotion WHERE id='{$webglobal['pid']}'");
	}
	if (empty($webglobal['pinfo']))
	{
		global_ShowMessage('没有对应条目', '', 'BACK');
	}

	if ($webglobal['doit']==1)
	{
		global_CheckPost(
				array(
					array('sitename,','str','','地点名称不能为空',1),
					array('begintime','datetime','','活动时间不能为空',1),
					array('city,','str','','活动城市不能为空',1),
					array('address,','str','','活动具体地址不能为空',1),
					array('latitude,','num','@!=0','地图位置必须设定',1),
					array('longitude,','num','','地图位置必须设定',1),
					array('telephone,','str','','联系电话不能为空',1),
					array('maxpeoplenum,','int','@>0','人数必须设定',1),
					array('info,','str','','',0,''),
					array('topic_input_name[]','str','','',0,''),
					array('topic_input_info[]','str','','',0,''),
					array('topic_input_order[]','int','','',0,0),
					array('topic_input_cover','int','','',0,0),
			));

		//json格式判断
		if ($webrequest['pagehead']=='ajax')
		{
			if (!empty($webglobal['CPM']))
			{
				echo '{"status":0,"errorinfo":"'.implode('<br />', $webglobal['CPM']).'"}';
			}
			else
			{
				echo '{"status":1}';
			}
			exit();
		}

		if (empty($webglobal['CPM']))
		{
			$webglobal['CPD']['begintime'] = empty($webglobal['CPP']['begintime']) ? $webserver['timestamp'] : global_ConvTime($webglobal['CPP']['begintime']);
			$webglobal['CPD']['addtime'] = $webserver['timestamp'];
			$webglobal['CPD']['pid'] = $webglobal['pid'];

			//相册处理
			//include_once WEBFILEPATH.'/include/image.class.php';
			//$tempimage = new Image();
			$webglobal['PIC'] = array();
			foreach ($webglobal['CPP']['topic_input_name'] as $tempkey => $tempvalue)
			{
				if ($tempvalue != '')
				{
					//$tempimage->OnceResize($tempvalue, 500, 500, $tempvalue.'.jpg', 0, 1);	//生成缩略图
					$webglobal['PIC'][$tempkey]['imgfile'] = $tempvalue;
					$webglobal['PIC'][$tempkey]['imginfo'] = isset($webglobal['CPP']['topic_input_info'][$tempkey]) ? $webglobal['CPP']['topic_input_info'][$tempkey] : '';
					$webglobal['PIC'][$tempkey]['imgorder'] = isset($webglobal['CPP']['topic_input_order'][$tempkey]) ? $webglobal['CPP']['topic_input_order'][$tempkey] : 0;
					if ($webglobal['CPP']['topic_input_cover'] == $tempkey)
					{
						$webglobal['CPD']['coverimg'] = $tempvalue;
					}
				}
			}
			//未设置封面自动设置
			if (!empty($webglobal['PIC']) && $webglobal['CPD']['coverimg']=='')
			{
				$tempfirstvalue = reset($webglobal['PIC']);
				$webglobal['CPD']['coverimg'] = $tempfirstvalue['imgfile'];
			}

			//写入
			$tempaddid = $db->Insert('promotion_site', '', TRUE);
			if (!$tempaddid)
			{
				global_ShowMessage('数据库操作失败，请重试。', '', 'BACK');
			}
			//更新相册
			if (!empty($webglobal['PIC']))
			{
				foreach ($webglobal['PIC'] as $tempvalue)
				{
					$tempvalue['sid'] = $tempaddid;
					$tempaddimageid = $db->Insert('promotion_site_img', $tempvalue, TRUE);
				}
			}
		}
		if (!empty($webglobal['CPM']))
		{
			global_ShowMessage($webglobal['CPM'], '', 'BACK');
		}
		else
		{
			global_ShowMessage('活动场所添加成功。', WEBURLPATH."/{$webserver['curfilename']}.php?action=site&pid={$webglobal['pid']}");
		}
	}
}
//场所编辑
elseif ($webglobal['action']=='siteedit')
{
	$webglobal['pid'] = isset($webrequest['pid']) ? intval($webrequest['pid']) : 0;
	$webglobal['sid'] = isset($webrequest['sid']) ? intval($webrequest['sid']) : 0;
	$webglobal['datainfo'] = array();
	if ($webglobal['sid'] > 0)
	{
		$webglobal['datainfo'] = $db->GetOne("SELECT * FROM promotion_site WHERE id='{$webglobal['sid']}' AND pid='{$webglobal['pid']}'");
	}
	if (empty($webglobal['datainfo']))
	{
		global_ShowMessage('没有对应条目', '', 'BACK');
	}
	$webglobal['datainfo']['begintime_show'] = global_FormatTime($webglobal['datainfo']['begintime']);
	//相册数据
	$webglobal['imagemaxid'] = 0;
	$webglobal['datainfo_image'] = array();
	$query = $db->Query("SELECT * FROM promotion_site_img WHERE sid='{$webglobal['sid']}' ORDER BY imgorder ASC,id ASC");
	while ($tempdata = $db->FetchArray($query))
	{
		$webglobal['imagemaxid'] = max($webglobal['imagemaxid'], $tempdata['id']);
		$tempdata['f'] = urlencode($tempdata['imgfile']);
		$webglobal['datainfo_image'][$tempdata['id']] = $tempdata;
	}

	//编辑提交
	if ($webglobal['doit']==1)
	{
		global_CheckPost(
				array(
					array('sitename,','str','','地点名称不能为空',1),
					array('begintime','datetime','','活动时间不能为空',1),
					array('city,','str','','活动城市不能为空',1),
					array('address,','str','','活动具体地址不能为空',1),
					array('latitude,','num','@!=0','地图位置必须设定',1),
					array('longitude,','num','','地图位置必须设定',1),
					array('telephone,','str','','联系电话不能为空',1),
					array('maxpeoplenum,','int','@>0','人数必须设定',1),
					array('info,','str','','',0,''),
					array('topic_input_name[]','str','','',0,''),
					array('topic_input_info[]','str','','',0,''),
					array('topic_input_order[]','int','','',0,0),
					array('topic_input_cover','int','','',0,0),
			));

		//json格式判断
		if ($webrequest['pagehead']=='ajax')
		{
			if (!empty($webglobal['CPM']))
			{
				echo '{"status":0,"errorinfo":"'.implode('<br />', $webglobal['CPM']).'"}';
			}
			else
			{
				echo '{"status":1}';
			}
			exit();
		}

		if (empty($webglobal['CPM']))
		{
			$webglobal['CPD']['begintime'] = empty($webglobal['CPP']['begintime']) ? $webserver['timestamp'] : global_ConvTime($webglobal['CPP']['begintime']);

			//相册处理
			//include_once WEBFILEPATH.'/include/image.class.php';
			//$tempimage = new Image();
			$webglobal['PIC'] = array();
			foreach ($webglobal['CPP']['topic_input_name'] as $tempkey => $tempvalue)
			{
				if ($tempvalue != '')
				{
					/*
					if ($tempkey > $webglobal['imagemaxid'])
					{
						$tempimage->OnceResize($tempvalue, 500, 500, $tempvalue.'.jpg', 0, 1);	//生成缩略图
					}
					*/
					$webglobal['PIC'][$tempkey]['imgfile'] = $tempvalue;
					$webglobal['PIC'][$tempkey]['imginfo'] = isset($webglobal['CPP']['topic_input_info'][$tempkey]) ? $webglobal['CPP']['topic_input_info'][$tempkey] : '';
					$webglobal['PIC'][$tempkey]['imgorder'] = isset($webglobal['CPP']['topic_input_order'][$tempkey]) ? $webglobal['CPP']['topic_input_order'][$tempkey] : 0;
					if ($webglobal['CPP']['topic_input_cover'] == $tempkey)
					{
						$webglobal['CPD']['coverimg'] = $tempvalue;
					}
				}
			}
			//未设置封面自动设置
			if (!empty($webglobal['PIC']) && $webglobal['CPD']['coverimg']=='')
			{
				$tempfirstvalue = reset($webglobal['PIC']);
				$webglobal['CPD']['coverimg'] = $tempfirstvalue['imgfile'];
			}

			//检查主数据更新
			$temptopicedit = GetDiffAry($webglobal['CPD'], $webglobal['datainfo']);
			//检查相册数据更新
			$tempimagedel = $tempimageedit = $tempimageadd = array();
			foreach ($webglobal['datainfo_image'] as $tempkey => $tempvalue)
			{
				if (!isset($webglobal['PIC'][$tempkey]))
				{
					$tempimagedel[] = $tempkey;
				}
				else
				{
					$tempdiff = GetDiffAry($webglobal['PIC'][$tempkey], $tempvalue);
					if (!empty($tempdiff))
					{
						$tempimageedit[$tempkey] = $tempdiff;
					}
				}
			}
			foreach ($webglobal['PIC'] as $tempkey => $tempvalue)
			{
				if (!isset($webglobal['datainfo_image'][$tempkey]))
				{
					$tempvalue['sid'] = $webglobal['sid'];
					$tempimageadd[] = $tempvalue;
				}
			}

			//编辑
			if (!empty($temptopicedit))
			{
				$db->Update('promotion_site', $temptopicedit, "id='{$webglobal['sid']}'");
			}
			if (!empty($tempimagedel))
			{
				$db->Delete('promotion_site_img', "sid='{$webglobal['sid']}' AND id IN (".$db->BuildInSql($tempimagedel).")");
			}
			if (!empty($tempimageedit))
			{
				foreach ($tempimageedit as $tempkey => $tempvalue)
				{
					$db->Update('promotion_site_img', $tempvalue, "sid='{$webglobal['sid']}' AND id='{$tempkey}'");
				}
			}
			if (!empty($tempimageadd))
			{
				foreach ($tempimageadd as $tempvalue)
				{
					$tempaddimageid = $db->Insert('promotion_site_img', $tempvalue, TRUE);
				}
			}
		}
		if (!empty($webglobal['CPM']))
		{
			global_ShowMessage($webglobal['CPM'], '', 'BACK');
		}
		else
		{
			global_ShowMessage('活动场所编辑成功。', WEBURLPATH."/{$webserver['curfilename']}.php?action=site&pid={$webglobal['pid']}");
		}
	}
}
//场所删除
elseif ($webglobal['action']=='sitedel')
{
	if ($webglobal['doit']==1)
	{
		$webglobal['pid'] = isset($webrequest['pid']) ? intval($webrequest['pid']) : 0;
		$webglobal['sid'] = isset($webrequest['sid']) ? intval($webrequest['sid']) : 0;
		if ($webglobal['pid']<=0 || $webglobal['sid']<=0)
		{
			global_ShowMessage('参数错误。', '', 'BACK');
		}
		else
		{
			$db->Delete('promotion_site', "id='{$webglobal['sid']}'");
			$db->Delete('promotion_site_img', "sid='{$webglobal['sid']}'");
			$db->Delete('promotion_user', "sid='{$webglobal['sid']}'");
			global_ShowMessage('活动场所删除成功。', WEBURLPATH."/{$webserver['curfilename']}.php?action=site&pid={$webglobal['pid']}");
		}
	}
	else
	{
		exit();
	}
}
//添加
elseif ($webglobal['action']=='add')
{
	if ($webglobal['doit']==1)
	{
		global_CheckPost(
				array(
					array('title,','str','','标题不能为空',1),
					array('cover_input_name,gifpic','str','','礼品图片必须上传',1),
					array('giftinfo,','html','','礼品介绍不能为空',1),
					array('content,','html','','活动内容不能为空',1),
					array('cover1_input_name,showimg','str','','活动展示图片必须上传',1),
			));

		//json格式判断
		if ($webrequest['pagehead']=='ajax')
		{
			if (!empty($webglobal['CPM']))
			{
				echo '{"status":0,"errorinfo":"'.implode('<br />', $webglobal['CPM']).'"}';
			}
			else
			{
				echo '{"status":1}';
			}
			exit();
		}

		if (empty($webglobal['CPM']))
		{
			$webglobal['CPD']['addtime'] = $webserver['timestamp'];
			//写入
			$tempaddid = $db->Insert('promotion', '', TRUE);
			if (!$tempaddid)
			{
				global_ShowMessage('数据库操作失败，请重试。', '', 'BACK');
			}
		}
		if (!empty($webglobal['CPM']))
		{
			global_ShowMessage($webglobal['CPM'], '', 'BACK');
		}
		else
		{
			global_ShowMessage('活动添加成功。', WEBURLPATH."/{$webserver['curfilename']}.php?action=list");
		}
	}
}
//编辑
elseif ($webglobal['action']=='edit')
{
	//读取当前信息
	$webglobal['id'] = isset($webrequest['id']) ? intval($webrequest['id']) : 0;
	$webglobal['datainfo'] = array();
	if ($webglobal['id'] > 0)
	{
		$webglobal['datainfo'] = $db->GetOne("SELECT * FROM promotion WHERE id='{$webglobal['id']}'");
	}
	if (empty($webglobal['datainfo']))
	{
		global_ShowMessage('没有对应条目', '', 'BACK');
	}
	$webglobal['datainfo']['gifpic_show'] = !empty($webglobal['datainfo']['gifpic']) ? urlencode($webglobal['datainfo']['gifpic']) : '';
	$webglobal['datainfo']['showimg_show'] = !empty($webglobal['datainfo']['showimg']) ? urlencode($webglobal['datainfo']['showimg']) : '';

	if ($webglobal['doit']==1)
	{
		global_CheckPost(
				array(
					array('title,','str','','标题不能为空',1),
					array('cover_input_name,gifpic','str','','礼品图片必须上传',1),
					array('giftinfo,','html','','礼品介绍不能为空',1),
					array('content,','html','','活动内容不能为空',1),
					array('cover1_input_name,showimg','str','','活动展示图片必须上传',1),
			));

		//json格式判断
		if ($webrequest['pagehead']=='ajax')
		{
			if (!empty($webglobal['CPM']))
			{
				echo '{"status":0,"errorinfo":"'.implode('<br />', $webglobal['CPM']).'"}';
			}
			else
			{
				echo '{"status":1}';
			}
			exit();
		}

		if (empty($webglobal['CPM']))
		{
			$tempedit = GetDiffAry($webglobal['CPD'], $webglobal['datainfo']);
			if (!empty($tempedit))
			{
				$db->Update('promotion', $tempedit, "id='{$webglobal['id']}'");
			}
		}
		if (!empty($webglobal['CPM']))
		{
			global_ShowMessage($webglobal['CPM'], '', 'BACK');
		}
		else
		{
			global_ShowMessage('活动修改成功。', WEBURLPATH."/{$webserver['curfilename']}.php?{$webglobal['gourl']}");
		}
	}
}
//删除
elseif ($webglobal['action']=='del')
{
	if ($webglobal['doit']==1)
	{
		global_CheckPost(
				array(
					array('checkid[]','int','','没有选择需要删除的条目！',1),
			));
		if (!empty($webglobal['CPM']))
		{
			global_ShowMessage($webglobal['CPM'], '', 'BACK');
		}
		else
		{
			$query = $db->Query("SELECT * FROM promotion_site WHERE pid IN (".$db->BuildInSql($webglobal['CPP']['checkid']).")");
			$webglobal['dataarray'] = array();
			while ($tempdata = $db->FetchArray($query))
			{
				$webglobal['dataarray'][] = $tempdata['id'];
			}
			$db->Delete('promotion', "id IN (".$db->BuildInSql($webglobal['CPP']['checkid']).")");
			$db->Delete('promotion_site', "pid IN (".$db->BuildInSql($webglobal['CPP']['checkid']).")");
			$db->Delete('promotion_user', "pid IN (".$db->BuildInSql($webglobal['CPP']['checkid']).")");
			if (!empty($webglobal['dataarray']))
			{
				$db->Delete('promotion_site_img', "sid IN (".$db->BuildInSql($webglobal['dataarray']).")");
			}
			global_ShowMessage('活动删除成功。', WEBURLPATH."/{$webserver['curfilename']}.php?{$webglobal['gourl']}");
		}
	}
	else
	{
		exit();
	}
}
//列表
elseif ($webglobal['action']=='list')
{
	$tempdefaultpagenum = 20;
	global_CheckPost(
				array(
					array('searchkey','str','','',0,''),
					array('perpage','int','@>0','',0,$tempdefaultpagenum),
			));

	//搜索条件处理
	$tempsearchsql = array();
	$webglobal['searchurl'] = "&action={$webglobal['action']}";	//搜索条件
	if ($webglobal['CPP']['searchkey'] != '')
	{
		$tempsearchfield = array('title');
		$tempsearchsql[] = $db->BuildSearchSql($webglobal['CPP']['searchkey'], $tempsearchfield);
		$webglobal['searchurl'] .= "&searchkey=".urlencode($webglobal['CPP']['searchkey']);
	}
	//排序设定处理
	$tempshowurl = '';
	if ($webglobal['CPP']['perpage'] != $tempdefaultpagenum)
	{
		$tempshowurl .= "&perpage={$webglobal['CPP']['perpage']}";
	}
	$webglobal['gourl'] = $webglobal['searchurl'].$tempshowurl."&page={$webrequest['page']}";	//整体页面条件
	$webglobal['gourlencode'] = urlencode($webglobal['gourl']);

	$tempsearchsql = empty($tempsearchsql) ? '' : ' WHERE '.implode(' AND ', $tempsearchsql);
	$webglobal['perpage'] = $webglobal['CPP']['perpage'];
	$webglobal['datanum'] = $db->GetNum("SELECT COUNT(*) FROM promotion{$tempsearchsql}");
	if ($webglobal['datanum'] > 0)
	{
		$webglobal['page'] = global_Page($webglobal['datanum'], $webglobal['perpage'], $webrequest['page'], WEBURLPATH."/{$webserver['curfilename']}.php?{$webglobal['searchurl']}{$tempshowurl}&page=@@");
		$tempstartnum = ($webrequest['page']-1)*$webglobal['perpage'];
		$temporderstr = "id DESC";
		$query = $db->Query("SELECT * FROM promotion{$tempsearchsql} ORDER BY {$temporderstr} LIMIT $tempstartnum, {$webglobal['perpage']}");
		$webglobal['dataarray'] = array();
		while ($tempdata = $db->FetchArray($query))
		{
			$webglobal['dataarray'][$tempdata['id']] = $tempdata;
		}
	}
}
else
{
	global_GoToUrl(WEBURLPATH."/{$webserver['curfilename']}.php?action=list");
}

template_Display($webserver['curfilename']);
